package housing.task6_web;

import housing.task3.dao.HsAddressDao;
import housing.task3.factory.HsAddressDaoFactory;
import org.apache.log4j.BasicConfigurator;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class InitContextListener implements ServletContextListener {
    public static final String CTX_ADDRESS_DAO = "hs_addressDao";

    private HsAddressDao addressDao;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        BasicConfigurator.configure();

        addressDao = HsAddressDaoFactory.create();
        sce.getServletContext().setAttribute(CTX_ADDRESS_DAO, addressDao);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        //  oughta do something smart here (i.e. force-closing connections)
    }
}
